import { defineStore } from 'pinia'
import { ref } from 'vue'

// 定义 Store
export const useOrderStore = defineStore(
  'order',
  () => {
    // 工单列表
    const orderList = ref([])

    // 设置工单信息
    const setOrderList = (arr) => {
      orderList.value = arr
    }

    const offlineOrderList = ref([])
    const setOfflineOrderList = (arr) => {
      offlineOrderList.value = arr
    }

    const clear = () => {
      orderList.value = []
      offlineOrderList.value = []
    }

    return {
      orderList,
      setOrderList,
      offlineOrderList,
      setOfflineOrderList,
      clear,
    }
  },
  {
    // 网页端配置
    // persist: true,
    // 小程序端配置
    persist: {
      storage: {
        getItem(key) {
          return uni.getStorageSync(key)
        },
        setItem(key, value) {
          return uni.setStorageSync(key, value)
        },
      },
    },
  },
)
